﻿<%@ WebHandler Language="C#" Class="list" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.Services;
using System.IO;
using System.Drawing;


public class list : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    private StringBuilder sb = null;
    public DataSet ds = null;
    public DataTable dt = null;
    private string sqlwhere = "";
    public void ProcessRequest (HttpContext context) {
        string type = PageBase.ext_string(context.Request.Params["type"]);
        switch (type)
        {

            //修改
            case "edit":
                edit(context);
                break;
            //查询高定配置信息
            case "getlist_byorderset":
                getlist_byorderset(context);
                break;
            default:
                //getinfo(context);
                break;
        }
    }
    //查询高定配置信息
    public void getlist_byorderset(HttpContext context)
    {

        string sql = @"select id,shrq_add,jjts,jjfy from [t_set]";
        DataTable dt = DBHelper.ExecuteDataTable(sql);

        sb = new StringBuilder();
        string code = "0";
        string msg = "";

        sb.Append("{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\",\"data\":[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("{\"id\":\"" + dt.Rows[i]["id"].ToString() + "\"");
            sb.Append(",\"shrq_add\":\"" + dt.Rows[i]["shrq_add"] + "\"");
            sb.Append(",\"jjts\":\"" + dt.Rows[i]["jjts"] + "\"");
            sb.Append(",\"jjfy\":\"" + dt.Rows[i]["jjfy"] + "\"}");
            if (i < dt.Rows.Count - 1)
            {
                sb.Append(",");
            }
        }
        sb.Append("]}");
        context.Response.Write(sb.ToString());
        context.Response.ContentType = "text/json";
        context.Response.End();
    }

    //修改
    public void edit(HttpContext context)
    {
        string isfirst = PageBase.ext_string(context.Request.Params["isfirst"]);
        string msg = "";
        string sqlsave = "";
        bool flag;
        GetDate list = new GetDate();
        using (System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream))
        {
            string s = sr.ReadToEnd();
            list = new JavaScriptSerializer().Deserialize<GetDate>(s);
        }
         string shrq_add = Utility.Trim(list.LoadData_type[0].shrq_add);
        string jjts = Utility.Trim(list.LoadData_type[0].jjts);
        string jjfy = Utility.Trim(list.LoadData_type[0].jjfy);
        string userid = Utility.Trim(list.LoadData_type[0].userid);
        if (isfirst == "true")
        {
            sqlsave = @"insert into  [t_set](shrq_add,jjts,jjfy,modifier,updatetime) values('{0}','{1}','{2}','{3}','{4}');";
        }
        else
        {
        sqlsave = @"update [t_set] set 
                                   [shrq_add]='{0}'
                                  ,[jjts]='{1}'
                                  ,[jjfy]='{2}'
                                  ,[modifier]='{3}'
                                  ,[updatetime]='{4}';";
        }

        sqlsave = string.Format(sqlsave,shrq_add, jjts, jjfy, userid, DateTime.Now.ToString());
        int zxcount = DBHelper.ExecuteNonQuery(sqlsave);
        if (zxcount > 0)
        {
            flag = true;
            msg = "修改成功";
        }
        else
        {
            flag = false;
            msg = "修改失败，请联系管理员";
        }

        context.Response.Write("{\"flag\":\"" + flag + "\",\"remsg\":\"" + msg + "\"}");
        context.Response.ContentType = "text/json";
        context.Response.End();
    }

    public class GetDate
    {
        public List<setmanager> LoadData_type { get; set; }
    }
    public class setmanager
    {
             //收货日期增加天数
        public string shrq_add;
        public string SHRQ_ADD
        {
            get { return shrq_add; }
            set { shrq_add = value; }
        }
        //加急天数
        public string userid;
        public string USERID
        {
            get { return userid; }
            set { userid = value; }
        }
        //加急天数
        public string jjts;
        public string JJTS
        {
            get { return jjts; }
            set { jjts = value; }
        }
        //加急费用
        public string jjfy;
        public string JJFY
        {
            get { return jjfy; }
            set { jjfy = value; }
        }

    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}